<div class="row">
<div class="col-xs-12">

<form class="form-horizontal" role="form" action="<?php echo DOMAIN_MAIN?>/admin/manage/add" method="post" id='add_user_submit'>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="data-admin-username">
			<span class="red">*</span>登录账号：
			</label>
			<div class="col-sm-9">
		    <input type="text" class="col-xs-10 col-sm-5"  name="username"  id="data-admin-username"
				   value="<?php echo set_value('username')?>" required maxlength="20">
			<label class="red" id="data-role-name-error"><?php echo form_error('username')?></label>
			</div>
		</div>
		<div class="space-4"></div>

		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="data-admin-pass">
		    <span class="red">*</span>密码：
		    </label>
			<div class="col-sm-9">
				<input type="password" class="col-xs-10 col-sm-5" name="pass"  id="data-admin-pass"
					   value="<?php echo set_value('pass')?>" required>
				<label class="red" id="data-role-pass-error"><?php echo form_error('pass')?></label>
			</div>
		</div>
		<div class="space-4"></div>


		<div class="form-group">
			
			<label class="col-sm-3 control-label no-padding-right" for="data-admin-nickname">管理员昵称：</label>
			
			<div class="col-sm-9">
				<input type="text" class="col-xs-10 col-sm-5"  name="nickname"  id="data-admin-nickname"
					   value="<?php echo set_value('nickname')?>" maxlength="40">
				<label class="red" id="data-role-nickname-error"><?php echo form_error('nickname')?></label>
			</div>
		</div>
		<div class="space-4"></div>
			
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right">
			<span class="red">*</span>管理员角色：
			</label>
			
			<div class="col-sm-4">
				<select class="form-control" name='rid'>
					<?php foreach( $roles as $e ):?>
					<option value=<?php echo $e['id']?>><?php echo $e['name']?></option>
					<?php endforeach;?>
				</select>
				<label class="red"><?php echo form_error('rid')?></label>
			</div>
		</div>
		
		<div class="clearfix form-actions">
			<div class="col-md-offset-3 col-md-9">
				<button class="btn btn-info btn-sm" type="submit">
					<i class="ace-icon fa fa-check bigger-110"></i>
					提交
				</button>

				&nbsp; &nbsp; &nbsp;
				<button class="btn btn-sm" type="reset">
					<i class="ace-icon fa fa-undo bigger-110"></i>
					重置
				</button>
			</div>
		</div>
		
</form>
</div>
</div>

<script type="text/javascript">

	$(document).on('keyup', '#data-admin-username', function () {

		var admin_name=$('#data-admin-username').val();
		var url='<?php echo DOMAIN_MAIN?>/api/permissions/check_admin_name';
		var params={
			admin_name:admin_name
		};

		$.get(url, params, function (data) {
			if(data.state=='success'){
				var new_dom='管理员名称已存在，请重新填写！';
				$("#data-role-name-error").html(new_dom);
				return false;
			}else{
				$("#data-role-name-error").html('');
				return true;
			}

		},'json');



	});

	$(document).on('keyup', '#data-admin-pass', function () {

		var admin_pass=$('#data-admin-pass').val();
		var url='<?php echo DOMAIN_MAIN?>/api/permissions/check_admin_pass';
		var params={
			admin_pass:admin_pass
		};

		$.get(url, params, function (data) {
			if(data.state=='success'){
				if(data.error_type==1){
					var new_dom='管理员密码须大于6位，请继续输入！';
				}else if(data.error_type==2){
					var new_dom='管理员密码须小于30位，请重新填写！';
				}

				$("#data-role-pass-error").html(new_dom);
				return false;
			}else{
				$("#data-role-pass-error").html('');
				return true;
			}

		},'json');



	});


	//鼠标离开用户名输入框时触发
	$(document).on('blur', '#data-admin-username', function () {

		var name=$('#data-admin-username').val();
		var length=name.length;
		if(length<1){
			$("#data-role-name-error").html('用户名不能为空！');
			return false;
		}else{

			var url='<?php echo DOMAIN_MAIN?>/api/permissions/has_special_character';
			var params={
				name:name
			};

			$.get(url, params, function (data) {
				if(data.state=='success'){
					var new_dom='名称存在非法字符，请重新填写！';
					$("#data-role-name-error").html(new_dom);
					return false;
				}else{
					$("#data-role-name-error").html('');
					return true;
				}

			},'json')

		}


	});

	//鼠标离开密码框时触发

	$(document).on('blur', '#data-admin-pass', function () {

		var admin_pass=$('#data-admin-pass').val();

		if(admin_pass==''){
			$("#data-role-pass-error").html('密码不能为空！');
			return false;
		}else if(admin_pass.length<6){
			$("#data-role-pass-error").html("管理员密码须大于6位，请继续输入！");
			$('#data-admin-pass').focus();
		}else{
			$("#data-role-pass-error").html('');
			return true;
		}

	});

</script>
